Smallest/Largest String in column - Mailing list pgsql-sql

From lynch@lscorp.com (Richard Lynch)
Subject Smallest/Largest String in column
Date
Msg-id v02140b59b1b6dc9d3a19@[207.152.64.133]
Whole thread Raw
List pgsql-sql
I need an SQL aggregate (or typecasting or function or whatever) that will
find the smallest item in a column of type text.  Actually, I need min/max
from each of 4 columns of type text.  That would be 8 total.  *ACTUALLY*, I
need the smallest/largest from all of *those*, but I reckon it would be a
bit much to ask SQL to do that in one shot... or maybe not.

I'd much rather do:

"select min(lastname), max(lastname, min(firstname), max(firstname),
min(business), max(business), min(band), max(band) from members;"

than the 8 selects that would otherwise be required, since I suspect it
will be a mite faster.  'Course, there's only a 130 rows now, and it will
only end up being 1000 or so in the end, I think...

Alas, the docs about aggregates don't exactly inspire me to think I can
handle this on my own, and I couldn't find it in the archives...

Anybody done this before... or do I have to use a lot of skull sweat to
figure out aggregates and functions and builtin types and primitives and
extensibility?  See, I *read* the manual, I just didn't understand it too
well. :-)

THANKS!

PS  Do I wanna try to overload the min/max aggregates, or would that be a
definite no-no?

PPS  As far as case-sensitivity goes... I guess I want to do whatever ORDER
BY does, unless there's some way to make that case-insensitive I haven't
learned yet.  In the ideal world, everything would be case-insensitive...
In the real world, I'm stuck with whatever of "ORDER BY" and "where blah >=
'A'" can be convinced to do.

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com



pgsql-sql by date:

Previous
From: Mariana Travassos Aguiar da Silva
Date:
Subject: Help
Next
From: Jeffrey Lyon
Date:
Subject: problem w/ DELETE